package com.lsl.entity;

import lombok.Data;
import java.io.Serializable;

@Data
public class Result<T> implements Serializable {
    private Integer code; // 响应码
    private T data;      // 响应数据
    private String message;   // 响应消息

    // 成功响应
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(200);
        result.setData(data);
        result.setMessage("success");
        return result;
    }

    // 错误响应
    public static <T> Result<T> error(Integer code, String msg) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setData(null);
        result.setMessage(msg);
        return result;
    }

    // 成功响应(无数据)
    public static <T> Result<T> success() {
        return success(null);
    }
}
